package cn.geminis.warehouse.service.delivery.entity;

import cn.geminis.lowcode.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.OneToMany;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Set;

/**
 * 入库单
 */
@Getter
@Setter
@UuidEntity
@QueryFilter
@CrudRepository
@CrudController(save = false, delete = false)
public class Delivery {

    /**
     * 单号
     */
    @Column(length = 36)
    private String no;

    /**
     * 计划出库库时间
     */
    @Column(nullable = false)
    private LocalDate planTime;

    /**
     * 发货时间
     */
    @Column
    private LocalDate transitTime;

    /**
     * 装载时间
     */
    @Column
    private LocalDate loadTime;

    /**
     * 总价
     */
    @Column(nullable = false)
    private BigDecimal price;

    /**
     * 备注
     */
    @Column(length = 2048)
    private String memo;

    /**
     * 状态
     */
    @Column(nullable = false)
    @Convert(converter = DeliveryState.DeliveryStateConvert.class)
    @QueryFilterProperty(propertyType = "cn.geminis.warehouse.service.delivery.entity.DeliveryState")
    private DeliveryState state;

    /**
     * 线路明细
     */
    @OneToMany(cascade = {CascadeType.ALL}, mappedBy = "delivery")
    @JsonIgnoreProperties("delivery")
    private Set<DeliveryRoute> routes;

    /**
     * 入库单明细
     */
    @OneToMany(cascade = {CascadeType.ALL}, mappedBy = "delivery")
    @JsonIgnoreProperties("delivery")
    private Set<DeliveryDetail> details;

}
